//
//  ViewController.m
//  UI21_fileManager
//
//  Created by 张张烨 on 16/1/6.
//  Copyright © 2016年 张张烨. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"%@",NSHomeDirectory());
    
    // fileManager 文件管理器
    NSFileManager *fManager = [NSFileManager defaultManager];
    // 添加文件夹
    // 缓存路径
    NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    // 文件夹路径
    NSString *filePath = [path stringByAppendingPathComponent:@"lol"];
    // 创建文件夹
    [fManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
    NSString *str = @"红红火火恍恍惚惚";
    [str writeToFile:[filePath stringByAppendingPathComponent:@"lol.txt"] atomically:YES encoding:NSUTF8StringEncoding error:nil];
    
    // 删除
    // 清除缓存: 删除Caches文件夹 系统会重新生成Caches文件夹
    [fManager removeItemAtPath:path error:nil];
    
   // 获取文件夹中的内容
    NSArray *pathArr =  [fManager contentsOfDirectoryAtPath:[path stringByAppendingPathComponent:@"lol"] error:nil];
    
    NSLog(@"%@",pathArr);
    
    // NSUserDefaults 保存在本地的plist文件 操作方式类似字典 通常用来保存一些简单的本地数据
    // 添加本地数据
    NSLog(@"~%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"login"]);
    // 添加数据
    [[NSUserDefaults standardUserDefaults] setObject:@"注销" forKey:@"login"];
    [[NSUserDefaults standardUserDefaults] setBool:@"注销" forKey:@"islogin"];
    NSLog(@"!%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"login"]);
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
